#include <CoOS.h>
#include <ff.h>
#include <Config.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <system_stm32f10x.h>
#include <stm32f10x_spi.h>
#include <stm32f10x_tim.h>
#include <misc.h>
#include <LCD_driver.h>
#include <USART_TERM.h>
#include <Fat_Func.h>
#include <DAC_STM32.h>
#include <ParseString.h>
#include <Command.h>
#include <VS1003_Audio_Decoder.h>
#include <Keypad4x4.h>
#include <LED_driver.h>
#include <ADC_STM32.h>

extern USART_TypeDef* USARTx;
extern CONNECT_type FLAG_CONNECT_TYPE;

extern int OUTx;
extern unsigned int flag_export_usart;
extern unsigned int flag_adc_alarm_maxmin;

//-CoOS variable--------------------------------------------------------------
//-task declare--------------------------------------------------------------
//-define function--------------------------------------------------------------
//-function for task using--------------------------------------------------------------
//-global variables--------------------------------------------------------------
//-user flags--------------------------------------------------------------
//---------------------------------------------------------------
int main(void) {
	//SystemInit();
	//set value for global variable
	FLAG_CONNECT_TYPE = CONNECT_TERMINAL;
	flag_export_usart = 0;
	lcd_current_line = 0;
	USARTTermInit();
	SwitchTIM2IRQ(DISABLE);
	SwitchUSART1IRQ(ENABLE);
	VS10xx_Func_Config();
	SPI_VS10xx_Config();
	SwitchSPI2IRQ(ENABLE);
	EXTI_2_Config();
	SwitchEXTI2IRQ(ENABLE);
	OUTPUT_USARTTerm;
	puts("config xong\r\n");
	HardReset_VS10xx();
	puts("hard reset\r\n");
	SoftReset_VS10xx();
	puts("reset xong\r\n");
	VS10xx_SetVol();
	puts("set vol xong\r\n");
	Test_Beep_VS10xx();
	while (1) {
		puts("loop1\r\n");
		SPI_VS10xx_Send(0x53);
		SPI_VS10xx_Send(0xEF);
		SPI_VS10xx_Send(0x6E);
		SPI_VS10xx_Send(0x44);

		SPI_VS10xx_Send(0x0);

		SPI_VS10xx_Send(0x0);

		SPI_VS10xx_Send(0x0);

		SPI_VS10xx_Send(0x0);

//		puts("loop2\r\n");
		delayms(500);
//		puts("loop3\r\n");
		SPI_VS10xx_Send(0x45);

		SPI_VS10xx_Send(0x78);

		SPI_VS10xx_Send(0x69);

		SPI_VS10xx_Send(0x74);

//		puts("loop4\r\n");
		delayms(500);
//		printf("loop5\r\n");
	}
}
